<template>
	<view class="parent-view">
		<swiper :current="tabIndex" class="swiper-box" @change="ontabchange">
			<swiper-item class="swiper-item" v-for="(tab,spIndex) in tabBars" :key="spIndex">
				<scroll-view class="swiper-sv" :scroll-y="true" lower-threshold="30" @scrolltolower="loadMoreList">
					<!-- 我的奖励 -->
					<view class="jl-view" v-if="tab.name=='我的奖励'">
						<view class="jl-top-view">
							<text class="jl-tx-txt">可提现:</text>
							<text class="jl-tx-count">{{shouYiData.unWithdraw}}</text>
							<text class="jl-more-btn" @click="goShangDian">商店</text>
							<view class="jl-ms-view" v-if="shouYiData.reward">
								<text class="jl-ms-txt">总收入：{{shouYiData.reward}}</text>
								<text class="jl-ms-txt">待结算：{{shouYiData.unWithdraw}}</text>
								<text class="jl-ms-txt">已提现：{{shouYiData.doWithdraw}}</text>
							</view>
						</view>
						<view class="jl-list" v-for="(jiangliItem,jiangliIndex) in jiangLiList">
							<view class="jl-list-desc-view">
								<view class="jl-desc-view" style="margin-top: 12rpx;">
									<view class="jl-desc-name" style="flex-direction: row;">
										<text style="color: #FF4206;">{{jiangliItem.name}}</text>
										<text style="color: #000000;">{{jiangliItem.title}}</text>
									</view>
									<text class="jl-desc-time-txt">奖励</text>
								</view>
								<view class="jl-desc-view" style="margin-bottom: 12rpx;">
									<text class="jl-desc-mobile">{{jiangliItem.createtime}}</text>
									<text class="jl-desc-time">{{jiangliItem.money}}</text>
								</view>
								<view style="width: 100%;background-color: #F5F6FA;height: 2rpx;"></view>
							</view>
						</view>
					</view>
					<!-- 修谱师 -->
					<view v-if="tab.name=='修谱师'">

					</view>
					<!-- 家谱馆 -->
					<view v-if="tab.name=='家谱馆'">

					</view>
					<!-- 收银台 -->
					<view v-if="tab.name=='收银台'">

					</view>
				</scroll-view>
			</swiper-item>
		</swiper>
		<LoginTipDialog :isShow="isShowLoginTip" dataSource="登录查看具体信息" @returnLoginTipDialog="returnLoginTipDialog" />
	</view>
</template>

<script>
	import request from '../index/request.js';
	import inputDialog from "@/components/input-dialog/input-dialog.vue";
	import LoginTipDialog from "@/components/login-tip-dialog/login-tip-dialog.vue";
	export default {
		components: {
			LoginTipDialog,inputDialog
		},
		data() {
			return {
				tabIndex: 0,
				tabBars: [
					{
						name: '我的奖励',
					}
				],
				dialogData:{
					title:"温馨提示",
					hint:"请输入绑定人的手机号",
					leftTxt:"取消",
					rightTxt:"确定",
					tag:"binding"
				},
				jiangLiPage: 1,
				jiangLiList: [],
				shouYiData:{},
				userData:{}
			}
		},
		methods: {
			onShow: function() {
				this.share.shareType = 0
			},
			onLoad: function(options) {
				this.appUtil.saveAppInviteId(options)
				for (var i = 0; i < this.tabBars.length; i++) {
					if(this.tabBars[i].name==options.title){
						this.tabIndex=i
					}
				}
				this.getUserData()
				this.getStatisticsCash()
				this.getJiangLiList()
			},
			getUserData: function() {
				var that = this
				var user = uni.getStorageSync("shiqin-user")
				this.userPQD = user.PQD
				request.post("api/user/index", {}).then(data => {
					that.userData = data;
					uni.setStorageSync("shiqin-user",data)
				})
			},
			
			ontabchange: function(e) {
				let index = e.target.current || e.detail.current;
				this.tabIndex = index;
			},
			loadMoreList: function(e) {
				switch (this.tabBars[this.tabIndex].name) {
					case '我的奖励':
						this.jiangLiPage++
						this.getJiangLiList()
						break
				}
			},
			getJiangLiList: function() {
				var that = this
				request.post("api/user/get_change_list", {
					page: that.jiangLiPage,
					type: 3
				}).then(data => {
					if (that.jiangLiPage == 1) {
						that.jiangLiList = data
					} else {
						for (var i = 0; i < data.length; i++) {
							that.jiangLiList.push(data[i])
						}
					}
				})
			},
			getStatisticsCash: function() {
				var that = this
				request.post("api/user/statistics_cash", {
				}).then(data => {
					this.shouYiData=data
				})
			},
			goShangDian:function(){
				uni.navigateTo({
					url:"../../shopping-home/index"
				})
			}
		}
	}
</script>

<style>
	@import "index.css";
</style>
